<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>前后端交互案例</title>
</head>
<body>
    <div>
        <h1>前后端调用交互案例</h1>
    </div>

    <script src="../js/axios.js"></script>
    <script>
        /**
		*  完成用户入库操作
		*  用法: axios.post(url地址,对象名称)
		* 	      axios.put(url地址, 对象名称)
		* 
		* 		  axios.get(url地址,{params: 对象名称})
		* 		  axios.delete(url地址,{params: 对象名称})
		*/

        /* let url1 = "http://localhost:8090/axios/saveUser"
         let user1 = {name:"tomcat",age:18,sex:"女"}
         axios.post(url1,user1)
         .then(function(promise){
            console.log(promise.data)
         }) */


            //定义axios请求的前缀
            axios.defaults.baseURL = "http://localhost:8090"
			//let url1 = "/axios/saveUser"
			let user1 = {name: "tomcat",age: 18, sex: "女"}
			axios.post("/axios/saveUser",user1)
				.then(function(promise){
					console.log(promise.data)
				})

            /**
				 * 1.定义一个方法
				 * 关键字: 
				 * 		1. async 标识函数
				 *      2. await
				 */
				async function saveUser(){
					let user2 = {name: "axios",age: 18, sex: "男"}
					let promise = await axios.post("/axios/saveUser",user2)
					console.log(promise.data)
				}
				 
				//2.调用方法
				saveUser()



                async function saveUser(){
					let user2 = {name: "axios",age: 18, sex: "男"}
					//let {conf: confv,data: datav,status: statusv} = await axios.post("/axios/saveUser",user2)
					let {data: result} = await axios.post("/axios/saveUser",user2)
					console.log(result)
				}
    </script>
</body>
</html>